/*
    扫描器类
*/
export default class Scanner {
    constructor(templateStr) {
        this.templateStr = templateStr
        console.log('scanner run',templateStr);
        //指针
        this.pos = 0;
        this.tail = templateStr;
    }
    scan(tag){
        if(this.tail.indexOf(tag) == 0){
            //tag有多长，指针后移多少位
            this.pos += tag.length;
            this.tail = this.templateStr.substring(this.pos)
        }
    }
    // 扫描指指定内容，并返回扫描过的字符
    scanUtil(stopTag){
        const pos_backup = this.pos
        //当tail的开头不是stopTag的时候，就说明还未扫描到stopTag
        while(this.tail.indexOf(stopTag) != 0 && !this.eos()){
            this.pos++;
            this.tail = this.templateStr.substr(this.pos);
        }

        return this.templateStr.substring(pos_backup,this.pos)
    }
    //判断指针是否到头,end of str
    eos() {
        return this.pos >= this.templateStr.length
    }
}